package SparkGraphXInAction

import org.apache.spark._
import org.apache.log4j.{Level, Logger}
import org.apache.spark.{SparkContext, SparkConf}
import org.apache.spark.SparkContext._
import org.apache.spark.graphx._
import org.apache.spark.graphx.Graph._
import org.apache.spark.rdd.RDD
import org.apache.spark.graphx.util.GraphGenerators

/**
  * Created by Administrator on 2017/4/25 0025.
  */
object TestStronlyConnectedComponents {
  def main(args: Array[String]): Unit = {
    //设置运行环境
    val conf = new SparkConf().setAppName("SimpleGraphX").setMaster("local")
    val sc = new SparkContext(conf)
    val g = Graph(sc.makeRDD((1L to 7L).map((_,""))),
      sc.makeRDD(Array(Edge(2L, 5L, ""), Edge(5L, 3L, ""), Edge(3L, 2L, ""),
        Edge(4L, 5L, ""),Edge(6L,7L, "")))).cache
    val xxx = g.connectedComponents.vertices.map(_.swap).groupByKey.map(_._2).collect
    for(x <- xxx){
      println(x)
    }
    val list_scc = g.stronglyConnectedComponents(10).vertices.map(_.swap).groupByKey.map(_._2).collect
    for(scc <- list_scc){
      println(scc)
    }
  }
}
